package org.sdnstproject.interlayer.OF13Protocal;

import java.util.HashMap;

import org.projectfloodlight.openflow.types.U32;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;

public class FuBarrierReply {
	private static final Logger log = LoggerFactory.getLogger(FuBarrierReply.class);
    public byte version = 4;
    public byte type = 21;
    public short length = 8;
    public long xid = 0x0L;//需要dummyswitch设置
    
    public FuBarrierReply() {
    	
    }
    
    public ByteBuf writeTo() {
    	ByteBuf bb = Unpooled.directBuffer();
        bb.writeByte(version);
        bb.writeByte(type);
        bb.writeShort(length);
        bb.writeInt(U32.t(xid));
        return bb;
    }
    
    public FuBarrierReply setField(String field, String value) {
		switch (field) {
		case "version":
			this.version = Byte.parseByte(value);
			break;
		case "type":
			this.type = Byte.parseByte(value);
			break;
		case "length":
			this.length = Short.parseShort(value);
			break;
		case "xid":
			this.xid = Long.parseLong(value);
			break;
		}
		return this;
	}
    
    public HashMap<String, String> FuBarrierReplyFields = new HashMap<String, String>() {
		{
			put("version","byte");
			put("type","byte");
			put("length","short");
			put("xid","long");
		}
    };
    
    @Override
    public String toString() {
        StringBuilder b = new StringBuilder("FuBarrierReplyVer13(");
        b.append("version=").append(version);
        b.append(", ");
        b.append("type=").append(type);
        b.append(", ");
        b.append("length=").append(length);
        b.append(", ");
        b.append("xid=").append(xid);
        b.append(")");
        return b.toString();
    }
}
